package org.aplikator.client.local.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;

public class ClosableTab extends Composite {

    public ClosableTab(final String caption, final Widget associate, final TabPanel tabPanel, final CloseListener listener) {
        HorizontalPanel panel = new HorizontalPanel();

        panel.add(new Label(caption));
        panel.add(new Button("x", new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (listener != null) {
                    listener.onClose();
                }
                tabPanel.remove(associate);
                tabPanel.selectTab(tabPanel.getWidgetCount() - 1);
            }
        }));
        initWidget(panel);
    }

}
